<?php
    session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/Style.css" />
        <link rel="stylesheet" type="text/css" href="css/blitzer/jquery-ui-1.8.custom.css" />
    </head>
    
    <body>
        <?php
            require('config.ini.php');
            $sql = "SELECT notice.noticeid, notice.noticehead, notice.noticecontent, notice.noticedatetime, noticetype.noticetypename FROM notice Left Join noticetype ON notice.noticetypeid = noticetype.noticetypeid ORDER BY notice.noticeid DESC LIMIT 0, 2";
            $result = mysql_query($sql);
        ?>
        <div id="wrap">
            <div id="header">
                <div id="head"><p id="systemname">บ้านรักสุขภาพ</p></div>
                <?php
                    $i = 1;
                    while($row=mysql_fetch_array($result)){
                ?>
                <div id="notice<?php echo $i; ?>" class="sub-notice">
                    <?php $datetime = date_create($row['3']); ?>
                    <h3 class="notice-head"><?php echo $row['4'] ?></h3>
                    <div class="notice-content">
                        <div class="notice-date"><p class="notice-month"><?php echo date_format($datetime, 'm'); echo "/".date_format($datetime, 'y'); ?></p><p class="notice-day"><?php echo date_format($datetime, 'd'); ?></p></div>
                        <div class="notice-title"><h4><a href="newsdetail.php?newsid=<?php echo $row['0']; ?>" style="text-decoration:none; color:#90BF88;"><?php echo $row['1']; ?></a></h4></div>
                        <div class="notice-essence"><a><?php echo substr($row['2'],0,450); ?></a></div>
                        <div class="clear-all"></div>
                    </div>
                </div>
                <?php
                    $i++;
                    }
                    mysql_free_result($result);
                ?>
                <div id="login" class="sub-notice">
                    <?php
                        if (isset($_SESSION['userid'])) {
                    ?> <p style="margin-bottom:10px;margin-top:15px;margin-left:100px;"><?php echo " ยินดีต้อนรับ คุณ ".$_SESSION['userid']; ?> <input type="button" value="ข้อมูลส่วนตัว" class="btn-profile" onClick="parent.location='profile.php'" /></p>
                    
                    <p style="margin-top:5px;margin-left:10px;">
                        <input type="button" value="คอร์ส เพิ่ม/ลด น้ำหนัก" class="btn-profile" onClick="parent.location='course.php'" />
                        <input type="button" value="รายงานอาหาร" class="btn-profile" onClick="parent.location='reportfood.php'" />
                        <input type="button" value="รายงานน้ำหนัก" class="btn-profile" onClick="parent.location='reportweight.php'" />
                        <input type="button" value="อาหารกับโรค" class="btn-profile" onClick="parent.location='userdiseasefood.php'" />
                        <input type="button" value="ออกจากระบบ" class="btn-profile" onClick="parent.location='logout.php'" />
                    </p>
                    <?php
                        } else {
                    ?>
                    <div id="form-login">
                        <form action="action.php" method="post">
                            <input type="text" name="username" id="username" class="input-login" />
                            <input type="password" name="userpassword" id="userpassword" class="input-login" />
                            <div class="clear-all"></div>
                            <input type="hidden" name="action" value="login" />
                            <input type="submit" value="เข้าสู่ระบบ" id="btn-login" />
                        </form>
                    </div> 
                    <div id="regis">
                        <input type="button" value="สมัครสมาชิก" class="btn-log-reg" onClick="parent.location='register.php'"  />
                    </div>
                    <?php
                        }
                    ?>
                </div>
                <div class="clear-all"></div>
            </div><div class="clear-all"></div>
            
            <div id="main-nav">
                <div id="main-cen">
                    <div class="div-nav"><a class="nav-link" href="index.php">หน้าแรก</a></div>
                    <div class="div-nav"><a class="nav-link" href="news.php">ข่าว</a></div>
                    <div class="div-nav"><a class="nav-link" href="bmi.php">คำนวณดัชนีมวลกาย</a></div>
                    <div class="div-nav"><a class="nav-link" href="product.php">ผลิตภัณฑ์</a></div>
                    <div class="div-nav"><a class="nav-link" href="webboard.php">กระดานสนทนา</a></div>
                    <div class="last-div-nav"><a class="nav-link" href="aboutus.php">ติดต่อเรา</a></div>
                    <div class="clear-all"></div>
                </div>
            </div>
            <div id="main-content">
                <div class="service-content2" style="width:970px;">
                    <h2 class="content-head">รายงานอาหาร</h2>
                        <div style="margin:10px;">
                        <?php
								if(isset($_GET['reportday'])) {
									if($_GET['reportday']!==""){
										$menudate = $_GET['reportday'];	
									} else {
										$menudate = date("d-m-Y");
									}
								} else {
									$menudate = date("d-m-Y");
								}
								?>
                        	<fieldset class="f-profile" style="width:460px; float:left;margin-bottom: 15px;"><legend class="le-profile">เรียกดูในวันที่ <?php echo $menudate; ?></legend>
                            <div style="margin: 1px 5px 5px 5px; padding-left:10px;">
                            	<form>
                                	<p>
                                	<input type="text" id="datepicker" name="reportday"  />
                                    <input class="btn-profile" type="submit" value="เรียกดู" />
                                    </p>
                                </form>
                            </div>
                            </fieldset>
                            
                            
                            
                            <fieldset class="f-profile"  style="width:470px; float:right;" id="fieldset-profile-height"><legend class="le-profile">ปริมาณสารอาหาร</legend>
                            <div style="margin:10px 5px 20px 5px; padding-left:10px;">
                            <table border="1px" bordercolor="#ACD054"  style="border-collapse:collapse;">
                            <?php
							$sql = "SELECT sex, agebegin, ageend, totalfat,saturatedfat,cholestoral,protein,carbohydrate,dietaryfiber,vitamina,thiamin,riboflavin,niacin,vitaminb6,folicacid,biotin,panlothenicacid,vitaminb12,vitaminc,vitamind,vitamine,vitamink,calcium,phosphorus,iron,iodine,magnesium,zinc,copper,potassium,sodium, manganese, selenium, fluoride, molybdenum, chromium, chloride FROM agenutritent  WHERE sex = (SELECT userdata.sex FROM userdata WHERE userid = '$_SESSION[userid]') AND agebegin <= (SELECT DATE_FORMAT(NOW(),'%Y')-SUBSTRING(userdata.brithday,1,4) AS userold FROM userdata WHERE userid = '$_SESSION[userid]') AND ageend >= (SELECT DATE_FORMAT(NOW(),'%Y')-SUBSTRING(userdata.brithday,1,4) AS userold FROM userdata WHERE userid = '$_SESSION[userid]')";
							$result = mysql_query($sql);
							$row = mysql_fetch_array($result);
							$sql1="SELECT ROUND(SUM(usermenudiet.foodcc*food.totalfat),2) as resulttotalfat, ROUND(SUM(usermenudiet.foodcc*food.saturatedfat),2) as resultsaturatedfat, ROUND(SUM(usermenudiet.foodcc*food.cholestoral),2) as resultcholestoral, ROUND(SUM(usermenudiet.foodcc*food.protein),2) as resultprotein, ROUND(SUM(usermenudiet.foodcc*food.carbohydrate),2) as resultcarbohydrate, ROUND(SUM(usermenudiet.foodcc*food.dietaryfiber),2) as resultdietaryfiber, ROUND(SUM(usermenudiet.foodcc*food.vitamina),2) as resultvitamina, ROUND(SUM(usermenudiet.foodcc*food.thiamin),2) as resultthiamin, ROUND(SUM(usermenudiet.foodcc*food.riboflavin),2) as resultriboflavin, ROUND(SUM(usermenudiet.foodcc*food.niacin),2) as resultniacin, ROUND(SUM(usermenudiet.foodcc*food.vitaminb6),2) as resultvitaminb6, ROUND(SUM(usermenudiet.foodcc*food.folicacid),2) as resultfolicacid, ROUND(SUM(usermenudiet.foodcc*food.biotin),2) as resultbiotin, ROUND(SUM(usermenudiet.foodcc*food.panlothenicacid),2) as resultpanlothenicacid, ROUND(SUM(usermenudiet.foodcc*food.vitaminb12),2) as resultvitaminb12, ROUND(SUM(usermenudiet.foodcc*food.vitaminc),2) as resultvitaminc, ROUND(SUM(usermenudiet.foodcc*food.vitamind),2) as resultvitamind, ROUND(SUM(usermenudiet.foodcc*food.vitamine),2) as resultvitamine, ROUND(SUM(usermenudiet.foodcc*food.vitamink),2) as resultvitamink, ROUND(SUM(usermenudiet.foodcc*food.calcium),2) as resultcalcium, ROUND(SUM(usermenudiet.foodcc*food.phosphorus),2) as resultphosphorus, ROUND(SUM(usermenudiet.foodcc*food.iron),2) as resultiron, ROUND(SUM(usermenudiet.foodcc*food.iodine),2) as resultiodine, ROUND(SUM(usermenudiet.foodcc*food.magnesium),2) as resultmagnesium, ROUND(SUM(usermenudiet.foodcc*food.zinc),2) as resultzinc, ROUND(SUM(usermenudiet.foodcc*food.copper),2) as resultcopper, ROUND(SUM(usermenudiet.foodcc*food.potassium),2) as resultpotassium, ROUND(SUM(usermenudiet.foodcc*food.sodium),2) as resultsodium, ROUND(SUM(usermenudiet.foodcc*food.manganese),2) as resultmanganese, ROUND(SUM(usermenudiet.foodcc*food.selenium),2) as resultselenium, ROUND(SUM(usermenudiet.foodcc*food.fluoride),2) as resultfluoride, ROUND(SUM(usermenudiet.foodcc*food.molybdenum),2) as resultmolybdenum, ROUND(SUM(usermenudiet.foodcc*food.chromium),2) as resultchromium, ROUND(SUM(usermenudiet.foodcc*food.chloride),2) as resultchloride FROM usermenudiet Left Join food ON usermenudiet.foodid = food.foodid WHERE usermenudiet.menudate = STR_TO_DATE('$menudate','%d-%m-%Y') AND usermenudiet.userid = '$_SESSION[userid]'";
								$result1 = mysql_query($sql1);
								$row1=mysql_fetch_array($result1);
									function colorDiv($set,$get){
										if ($get == "0") {
											echo "lightGrey";
											//echo "";
										} else {
											if($set > $get) { 
												echo "yellow"; 
											} else if ($set == $get) { 
												echo "green"; 
											} else if ($set < $get) { 
												echo "red"; 
											} 
										}
									}
										function percentage($set,$get){
											if($get == "0"){
												//echo "ไม่สามารถหาได้";
												echo "<img style='width:24px; height:24px; vertical-align:middle;' src='images/warning.png'>";
											} elseif ($set == "0") {
												echo "0";
											} else {
												echo $percentage = round(($get/$set)*100,2);
											}
										}
							?>
                            <thead>
                              <tr>
                                <th style="width:165px;">สารอาหาร</th>
                                <th style="width:85px;">ต้องการ</th>
                                <th style="width:85px;">ได้รับ</th>
                                <th style="width:85px;">คิดเป็น %</th>
                              </tr>
                              </thead>
                              <tbody class="tbody-food">
                              <tr>
                                <td>ไขมันทั้งหมด(g)</td>
                                <td><?php echo $set = round($row['3'], 2);  ?></td>
                                <td><?php echo $get = round($row1['0'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ไขมันอิ่มตัว(g)</td>
                                <td><?php echo $set = round($row['4'], 2);  ?></td>
                                <td><?php echo $get = round($row1['1'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>โคเลสตอรอล (mg)</td>
                                <td><?php echo $set = round($row['5'], 2);  ?></td>
                                <td><?php echo $get = round($row1['2'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>โปรตีน (mg)</td>
                                <td><?php echo $set = round($row['6'], 2);  ?></td>
                                <td><?php echo $get = round($row1['3'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>คาร์โบไฮเดรต (g)</td>
                                <td><?php echo $set = round($row['7'], 2);  ?></td>
                                <td><?php echo $get = round($row1['4'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ใยอาหาร (g)</td>
                                <td><?php echo $set = round($row['8'], 2);  ?></td>
                                <td><?php echo $get = round($row1['5'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินเอ (ug RE)</td>
                                <td><?php echo $set = round($row['9'], 2);  ?></td>
                                <td><?php echo $get = round($row1['6'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินบี 1 (mg)</td>
                                <td><?php echo $set = round($row['10'], 2);  ?></td>
                                <td><?php echo $get = round($row1['7'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินบี 2 (mg)</td>
                                <td><?php echo $set = round($row['11'], 2);  ?></td>
                                <td><?php echo $get = round($row1['8'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ไนอะซิน (mg NE)</td>
                                <td><?php echo $set = round($row['12'], 2);  ?></td>
                                <td><?php echo $get = round($row1['9'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินบี 6 (mg)</td>
                                <td><?php echo $set = round($row['13'], 2);  ?></td>
                                <td><?php echo $get = round($row1['10'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>โฟลีค แอซิด (ug)</td>
                                <td><?php echo $set = round($row['14'], 2);  ?></td>
                                <td><?php echo $get = round($row1['11'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ไบโอติน (ug)</td>
                                <td><?php echo $set = round($row['15'], 2);  ?></td>
                                <td><?php echo $get = round($row1['12'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>แพนโทธินิค แอซิด (mg)</td>
                                <td><?php echo $set = round($row['16'], 2);  ?></td>
                                <td><?php echo $get = round($row1['13'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินบี 12 (ug)</td>
                                <td><?php echo $set = round($row['17'], 2);  ?></td>
                                <td><?php echo $get = round($row1['14'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินซี (mg)</td>
                                <td><?php echo $set = round($row['18'], 2);  ?></td>
                                <td><?php echo $get = round($row1['15'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินดี (ug)</td>
                                <td><?php echo $set = round($row['19'], 2);  ?></td>
                                <td><?php echo $get = round($row1['16'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินอี (mga-TE)</td>
                                <td><?php echo $set = round($row['20'], 2);  ?></td>
                                <td><?php echo $get = round($row1['17'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>วิตามินเค (ug)</td>
                                <td><?php echo $set = round($row['21'], 2);  ?></td>
                                <td><?php echo $get = round($row1['18'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>แคลเซียม (mg)</td>
                                <td><?php echo $set = round($row['22'], 2);  ?></td>
                                <td><?php echo $get = round($row1['19'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ฟอสฟอรัส (mg)</td>
                                <td><?php echo $set = round($row['23'], 2);  ?></td>
                                <td><?php echo $get = round($row1['20'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>เหล็ก (mg)</td>
                                <td><?php echo $set = round($row['24'], 2);  ?></td>
                                <td><?php echo $get = round($row1['21'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ไอโอดีน (ug)</td>
                                <td><?php echo $set = round($row['25'], 2);  ?></td>
                                <td><?php echo $get = round($row1['22'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>แมกนีเซียม (mg)</td>
                                <td><?php echo $set = round($row['26'], 2);  ?></td>
                                <td><?php echo $get = round($row1['23'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>สังกะสี (mg)</td>
                                <td><?php echo $set = round($row['27'], 2);  ?></td>
                                <td><?php echo $get = round($row1['24'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ทองแดง (mg)</td>
                                <td><?php echo $set = round($row['28'], 2);  ?></td>
                                <td><?php echo $get = round($row1['25'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>โพแทสเซียม (mg)</td>
                                <td><?php echo $set = round($row['29'], 2);  ?></td>
                                <td><?php echo $get = round($row1['26'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>โซเดียม (mg)</td>
                                <td><?php echo $set = round($row['30'], 2);  ?></td>
                                <td><?php echo $get = round($row1['27'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>แมงกานีส (mg)</td>
                                <td><?php echo $set = round($row['31'], 2);  ?></td>
                                <td><?php echo $get = round($row1['28'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ซีลีเนียม (ug)</td>
                                <td><?php echo $set = round($row['32'], 2);  ?></td>
                                <td><?php echo $get = round($row1['29'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>ฟลูออไรด์ (mg)</td>
                                <td><?php echo $set = round($row['33'], 2);  ?></td>
                                <td><?php echo $get = round($row1['30'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>โมลิบตินัม (ug)</td>
                                <td><?php echo $set = round($row['34'], 2);  ?></td>
                                <td><?php echo $get = round($row1['31'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>โครเมียม (ug)</td>
                                <td><?php echo $set = round($row['35'], 2);  ?></td>
                                <td><?php echo $get = round($row1['32'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              <tr>
                                <td>คลอไรด์ (mg)</td>
                                <td><?php echo $set = round($row['36'], 2);  ?></td>
                                <td><?php echo $get = round($row1['33'], 2); ?></td>
                                <td><div style="background-color:<?php colorDiv($set,$get); ?>;"><?php percentage($set,$get); ?></div></td>
                              </tr>
                              </tbody>
                            </table>
                            <p style="height:30px; margin:10px 0;"><img style="width:24px; height:24px; vertical-align:middle;" src="images/warning.png"> ไม่สามารถหาค่าได้
                            </div>
                            </fieldset>
                            <fieldset class="f-profile" style="width:460px; float:left;margin-bottom: 15px;"><legend class="le-profile">เพิ่มรายการอาหาร</legend>
                            <div style="margin: 1px 5px 5px 5px; padding-left:10px;">
                            <table>
                            	<thead>
                                	<tr>
                                    	<th  style="border:1px solid #ACD054; width:30px;">มื้อ</th>
                                        <th style="border:1px solid #ACD054; width:190px;">อาหาร</th>
                                        <th style="text-align:center;border:1px solid #ACD054; width:50px;">ปริมาณ</th>
                                        <th style="text-align:center;border:1px solid #ACD054; width:50px;">หน่วย</th>
                                        <th  style="text-align:center;border:1px solid #ACD054; width:80px;">พลังงาน</th>
                                    </tr>
                                </thead>
                                <tbody>
                            <?php
								$sql = "SELECT usermenudiet.userid,usermenudiet.menudate,usermenudiet.menumeal,usermenudiet.foodcc, food.foodname, food.foodunit,food.totalcallory FROM usermenudiet LEFT JOIN food ON usermenudiet.foodid = food.foodid WHERE usermenudiet.userid = '$_SESSION[userid]' AND usermenudiet.menudate = STR_TO_DATE('$menudate','%d-%m-%Y')";
								$result = mysql_query($sql);
								$resultkk =	 0;
								while($row=mysql_fetch_object($result)) {
								if ($row->menumeal == '1') {
								$menumeal = "เช้า";
								$img = "Mostly Sunny-48.png";
								} else if ($row->menumeal == '2') {
								$menumeal = "กลางวัน";
								$img = "sunny-48.png";
								} else if ($row->menumeal == '3') {
								$menumeal = "เย็น";
								$img = "night-few-clouds-48.png";
								}
							?>
                            <tr>
                            	<td style="text-align:center;border:1px solid #ACD054; width:30px;"><img style="width:24px; height:24px;" src="images/<?php echo $img; ?>"></td>
                                <td style="border:1px solid #ACD054; width:190px;"><?php echo $row->foodname; ?></td>
                                <td style="text-align:center;border:1px solid #ACD054; width:50px;"><?php echo $row->foodcc; ?></td>
                                <td style="text-align:center;border:1px solid #ACD054; width:50px;"><?php echo $row->foodunit; ?></td>
                                <td style="text-align:center;border:1px solid #ACD054; width:80px;"><?php echo $total = $row->totalcallory*$row->foodcc; $resultkk += $total; ?></td>
                            </tr>
                            <?php
							}
							mysql_free_result($result);
							?>
                            </tbody>
                            </table>
                            <p style="height:30px;margin:10px 0;"><img style="width:24px; height:24px; vertical-align:middle;" src="images/Mostly Sunny-48.png"> มื้อเช้า      <img style="width:24px; height:24px; vertical-align:middle;" src="images/sunny-48.png"> มื้อกลางวัน       <img style="width:24px; height:24px; vertical-align:middle;" src="images/night-few-clouds-48.png"> มื้อค่ำ</p>
                            <?php echo "<p>วันนี้ได้รับพลังงานทั้งหมด ".$resultkk." กิโลแคลอรี่</p>"; ?>
                            <?php
							  $sql = "SELECT  usercourse.userid,usercourse.course,usercourse.courseday,usercourse.coursestartdate,usercourse.courseenddate,usercourse.totalcalorie,usercourse.resultcalorie,usercourse.coursekilo,usercourse.usercourseid FROM usercourse WHERE (SELECT Max(usercourse.usercourseid) FROM usercourse where userid = '$_SESSION[userid]') AND STR_TO_DATE('$menudate','%d-%m-%Y') BETWEEN usercourse.coursestartdate AND usercourse.courseenddate";
							  $result = mysql_query($sql);
							  $numrowresult = mysql_num_rows($result);
							  $row = mysql_fetch_array($result);
							  //echo $numrowresult;
							  if($numrowresult>1) {
								if ($row['1'] == "1" ) { $coursestr = "เพิ่ม"; } else { $coursestr = "ลด"; }
								echo "<p>คุณได้ลงคอร์ส{$coursestr}น้ำหนักจำนวน {$row['7']} กิโลกรัม</p>";
								echo "<p>ต้องได้รับพลังงานรวมทั้งหมด {$row['6']} กิโลแคลอรี่ต่อวัน</p>";
								if ($resultkk > $row['6']) { $resultstr = $resultkk-$row['6']; echo "<p style='background-color:red;font-weight:bold;'>คุณได้รับพลังงานเกินมา $resultstr กิโลแคลอรี่</p>"; }
							  } mysql_free_result($result);
							  ?>
                            <?php
								$sql = "SELECT food.foodid, food.foodname FROM food WHERE food.status = '1'";
								$result = mysql_query($sql);
								$foodoption = "";
								while ($row=mysql_fetch_array($result)) {
									$foodoption .= "<option value='{$row[0]}'>{$row[1]}</option>";
								}
								mysql_free_result($result);
								/*
							  $sql = "SELECT  usercourse.userid,usercourse.course,usercourse.courseday,usercourse.coursestartdate,usercourse.courseenddate,usercourse.totalcalorie,usercourse.resultcalorie,usercourse.coursekilo,usercourse.usercourseid FROM usercourse WHERE (SELECT Max(usercourse.usercourseid) FROM usercourse where userid = 'akejionioni') and '$menudate' BETWEEN DATE_FORMAT('usercourse.coursestartdate,'%d-%m-%Y') AND DATE_FORMAT('usercourse.courseenddate,'%d-%m-%Y')";
							  $result = mysql_query($sql);
							  $numrowresult = mysql_num_rows($result);
							  $row = mysql_fetch_array($result);
							  if($numrowresult=1) {
								if ($row['1'] == "1" ) { $coursestr = "เพิ่ม"; } else { $coursestr = "ลด"; }
								echo "<p>คุณได้ลงคอร์ส{$coursestr}น้ำหนักจำนวน {$row['7']} กิโลกรัม</p>";
								echo "<p>ต้องได้รับพลังงานรวมทั้งหมด {$row['6']} กิโลแคลอรี่ต่อวัน</p>";
								if ($resultkk > $row['6']) { $resultstr = $resultkk-$row['6']; echo "<p style='background-color:red;font-weight:bold;'>คุณได้รับพลังงานเกินมา $resultstr กิโลแคลอรี่</p>"; }
							  }
							  */
							  ?>
                              <form method="post" action="action.php">
                                  <p class="p-reportfood"><label for="mealdate" class="l-reportfood">วันที่ </label><input class="i-reportfood" type="text" name="mealdate" id="mealdate" /></p>
                                  <p class="p-profile"><label for="menumeal" class="l-reportfood">มื้อ </label>
                                  <select name="menumeal" class="i-reportfood" id="menumeal">
                                  <option value="1">เช้า</option>
                                  <option value="2">กลางวัน</option>
                                  <option value="3">เย็น</option>
                                  </select></p>
                                  <p class="p-reportfood"><label for="foodid" class="l-reportfood">อาหาร</label><select class="i-reportfood" name="foodid" id="foodid"><? echo $foodoption; ?></select></p>
                                  <p class="p-profile"><label for="foodcc" class="l-reportfood">ปริมาณ</label><input class="i-reportfood" type="text" name="foodcc" id="foodcc" value="1"/></p>
                                  <input type="hidden" name="action" value="reportmeal" />
                                  <p><input class="btn-profile" type="submit" value="รายงานอาหาร" /> </p>
                               </form>
                            </div>
                            </fieldset>
                            
                            
                            
                            <fieldset class="f-profile" style="width:460px; float:left;margin-bottom: 15px;"><legend class="le-profile">ระบบสนันสนุนการตัดสินใจ</legend>
                                <div style="margin: 1px 5px 5px 5px;padding-left:10px;">
                                <?php
		  $sql = "SELECT menudietexample.menudate, menudietexample.menumeal, menudietexample.foodid, menudietexample.foodcc, food.foodname, menudietexample.exmenuid FROM menudietexample Left join food on menudietexample.foodid = food.foodid WHERE menudietexample.menudate = STR_TO_DATE('$menudate','%d-%m-%Y') AND menudietexample.userid = '$_SESSION[userid]' order by menudietexample.menumeal ASC";
		  $result = mysql_query($sql);
		  $nummenufood = mysql_num_rows($result);
		  $img = "";
		  if ($nummenufood==0){
		  	echo "ยังไม่มีการสร้างเมนูอาหาร";
		  }
		  else
		  { ?>
		  <table>
          <thead>
          <tr>
            <th style="border:1px solid #ACD054; width:30px;">มื้อ</th>
            <th style="border:1px solid #ACD054; width:250px;">ชื่ออาหาร</th>
            <th style="border:1px solid #ACD054; width:130px;">พลังงานที่ได้รับ</th>
          </tr>
          </thead>
          <tbody>
          <?php
		  while ($row=mysql_fetch_object($result)) {
		  if ($row->menumeal == '1') {
			$menumeal = "เช้า";
			$img = "Mostly Sunny-48.png";
		} else if ($row->menumeal == '2') {
			$menumeal = "กลางวัน";
			$img = "sunny-48.png";
		} else if ($row->menumeal == '3') {
			$menumeal = "เย็น";
			$img = "night-few-clouds-48.png";
		}
		  ?>
          <tr>
            <td style="text-align:center;border:1px solid #ACD054; width:30px;"><img style="width:24px; height:24px;" src="images/<?php echo $img; ?>"></td>
            <td style="border:1px solid #ACD054; width:250px;"><?php if($row->foodid == 0) { echo "ชาละลายไขมัน"; } else { echo $row->foodname; } ?></td>
            <td style="border:1px solid #ACD054; width:130px; text-align:center;"><?php echo $row->foodcc; ?></td>
          </tr>
          <?php
		  } mysql_free_result($result);
		  ?>
          </tbody>
        </table>
        <p style="height:30px;margin:10px 0;"><img style="width:24px; height:24px; vertical-align:middle;" src="images/Mostly Sunny-48.png"> มื้อเช้า      <img style="width:24px; height:24px; vertical-align:middle;" src="images/sunny-48.png"> มื้อกลางวัน       <img style="width:24px; height:24px; vertical-align:middle;" src="images/night-few-clouds-48.png"> มื้อค่ำ</p>
          
		  <?php } ?>
                                </div>
                            </fieldset>
                            
                            
                            
                            <fieldset class="f-profile" style="width:460px; float:left;margin-bottom: 15px;"><legend class="le-profile">อาหารที่เหมาะสมกับโรคประจำตัวของคุณ</legend>
                            	<div style="margin: 1px 5px 5px 5px;padding-left:10px;">
                                	<table>
                                    	<thead>
                                        	<tr>
                                            	<th>โรคประจำตัว</th>
                                                <th>อาหาร</th>
                                                <th>ความเหมาะสม</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <?php
											$sql = "SELECT diseasefood.diseaseid, diseasefood.foodid, diseasefood.foodtype, diseasefood.description, food.foodname ,diseasename FROM diseasefood LEFT JOIN food ON diseasefood.foodid = food.foodid LEFT JOIN disease ON diseasefood.diseaseid = disease.diseaseid WHERE diseasefood.diseaseid IN (SELECT userdisease.diseaseid FROM userdisease WHERE userdisease.userid = '$_SESSION[userid]')";
											$result = mysql_query($sql);
											$img = "";
											while ($row = mysql_fetch_array($result)) {
											if($row['2']=="0"){ $img = "yellow_light.png"; } else { $img = "green_light.png"; }									
										?>
                                        	<tr>
                                            	<td style="border:1px solid #ACD054; width:160px;"><?php echo $row['5']; ?></td>
                                                <td style="border:1px solid #ACD054; width:130px;"><?php echo $row['4']; ?></td>
                                                <td style=" text-align:center;border:1px solid #ACD054; width:120px;"><img style="width:24px; height:24px;" src="images/<?php echo $img; ?>"></td>
                                            </tr>
                                            <?php
											}
												mysql_free_result($result);
												mysql_close($link);
											?>
                                        </tbody>
                                    </table>
                                    <p style="height:30px; margin:10px 0;"><img style="width:24px; height:24px; vertical-align:middle;" src="images/green_light.png"> เหมาะสม   <img style="width:24px; height:24px; vertical-align:middle;" src="images/yellow_light.png"> ไม่เหมาะสม</p>
                                </div>
                            </fieldset>
                            
                            
                            
                        </div>
              </div><div class="clear-all">
            </div>
            <div id="footer">
                <div id="right-footer">
                    <div id="f-systemname"><span>บ้านรักสุขภาพ</span></div>
                    <div id="f-navi">
                        <div class="first-f-link f-link"><a href="index.php">หน้าแรก</a></div>
                        <div class="first-f-link f-link"><a href="news.php">ข่าว</a></div>
                        <div class="first-f-link f-link"><a href="bmi.php">คำนวณดัชนีมวลกาย</a></div>
                        <div class="first-f-link f-link"><a href="product.php">ผลิตภัณฑ์</a></div>
                        <div class="first-f-link f-link"><a href="webboard.php">กระดานสนทนา</a></div>
                        <div class="f-link"><a href="aboutus.php">ติดต่อเรา</a></div>
                        <div class="clear-all"></div>
                    </div>
                    <p class="f-darkgreen">ระบบสนับสนุนการตัดสินใจเลือกอาหารเพื่อควบคุมน้ำหนัก และแจ้งเตือนรายการอาหารผ่านโทรศัพท์มือถือ</p>
                    <p class="f-darkgreen">กรณีศึกษา บ้านรักสุขภาพ สาขา ตลาดวัดไชยฉิมพลี</p>
                </div>
                <div id="left-footer">
                    <p><span class="f-titlegreen">ที่อยู่ :</span></p>
                    <p><span class="f-contentwhite">27 / 94 หมู่ 6 แขวงบางแวก เขตภาษีเจริญ จังหวัดกรุงเทพมหานคร 10160</span></p>
                    <p><span class="f-titlegreen">โทรศัพท์ : </span><span class="f-contentwhite">024102209</span></p>
                    <!--<p><span class="f-titlegreen">แฟกซ์ : </span><span class="f-contentwhite">XX-XXX-XXXX</span></p>
                    <p><span class="f-titlegreen">อีเมลล์ : </span><span class="f-contentwhite">xxxx@xxxx.com</span></p>-->
                </div><div class="clear-all">
                </div>
            </div>
        </div>
       
        <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js"></script>
        <script type="text/javascript" src="js/jquery.corner.js"></script>
        <script type="text/javascript" src="js/jquery.watermarkinput.js"></script>
        <script type="text/javascript" src="js/jquery.ui.datepicker-th.js"></script>
        <script type="text/javascript">
            $(".service-content2").corner();
			$("#username").Watermark("ชื่อบัญชีผู้ใช้","#FFF");
			$("#userpassword").Watermark("รหัสผ่าน","#FFF");
			$("#datepicker,#mealdate").datepicker($.datepicker.regional['th']);
			//$('#datepicker').datepicker('option', { dateFormat: "yy-mm-dd" });
			$('#datepicker,#mealdate').datepicker('option', { dateFormat: "dd-mm-yy" });
			$("#ui-datepicker-div").css("font-size","80%").css("top","-1");
			//$('#datepicker').val(<?php echo $menudate; ?>);
			/* zebra tr
				var trzebra = $("tbody.tbody-food > tr");
				var i = 0;
				function zebra(i,obj) {
				   
					if(i % 2 == 0) {
					   $(obj).css("background-color","#FFFFFF"); 
					} else {
						   $(obj).css("background-color","#ECECEC"); 
				   } 
				}
				$.each(trzebra,function(){  zebra(i,$(this));  i++; });
				$("tbody tr").hover(function(){ $(this).addClass('hovertr'); },function(){ $(this).removeClass('hovertr'); });
		end	*/ 
        </script>
    </body>
</html>